import 'package:flutter/material.dart';

class FunctionItem extends StatelessWidget {
  const FunctionItem({
    Key? key,
    required this.label,
    required this.subLabel,
    required this.target
  }) : super(key: key);

  final String label;
  final String subLabel;
  final Widget target;

  Route _createRoute(Widget page) {
    return PageRouteBuilder(
      pageBuilder: (context, animation, secondaryAnimation) => page,
      transitionsBuilder: (context, animation, secondaryAnimation, child) {
        const begin = Offset(1.0, 0.0);
        const end = Offset.zero;
        const curve = Curves.ease;

        var tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve));

        return SlideTransition(
          position: animation.drive(tween),
          child: child,
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        ListTile(
          title: Text(label),
          subtitle: Text(subLabel),
          trailing: const Icon(Icons.keyboard_arrow_right),
          onTap: () {
            // Navigator.of(context).push(
            //   _createRoute(target)
            // );
            Navigator.of(context).push(
              MaterialPageRoute(builder: (_) => target)
            );
          },
        ),
        const Divider(height: 1, indent: 16,)
      ],
    );
  }
}
